package cn.xf.controller;

import cn.xf.domain.Orders;
import cn.xf.service.IOrdersService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author xiaofu
 * @date 2021-05-14 9:47
 * @email dearaf@163.com
 */
@Controller
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    /**
     * 分页查询所有
     *
     * @param page
     * @param pageSize
     * @return
     * @throws Exception
     */
    @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue = "1") Integer page, @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize)   {
        List<Orders> ordersList = ordersService.findAllByPage(page, pageSize);
        //分页对象封装
        PageInfo<Orders> pageInfo = new PageInfo<Orders>(ordersList);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("orders/orders-list");
        mv.addObject("pageInfo", pageInfo);
        return mv;
    }

    /**
     * 根据订单ID查询订单
     * 一个订单对应一个产品，为一个会员所有
     * 一个订单中包含多位旅客
     * @param
     * @return
     */
    @RequestMapping("/findById.do")
    public ModelAndView findById(@RequestParam("orderId") String orderId,@RequestParam("handleId") String handleId){
        Orders orders = ordersService.findById(orderId);
        ModelAndView mv = new ModelAndView();
        if("0".equals(handleId)){
            mv.setViewName("orders/orders-show");
        }else if("1".equals(handleId)){
            mv.setViewName("orders/orders-audit");
        }
        mv.addObject("orders", orders);
        return mv;
    }

}
